<?php

// $HLTest = false;

// function HLLog($data, $doIt=false) {
//   global $HLTest;
//   if ($doIt) {
//     echo $data;
//     echo '<br>';
//   } else if ($HLTest) {
//     echo $data;
//     echo '<br>';
//   }
// }
// function HLInfo($data) {
//   global $HLTest;
//   if ($HLTest) {
//     echo '<p style="color:blue;">' . $data . '</p>';
//     echo '<br>';
//   }
// }
// function HLWarn($data) {
//   global $HLTest;
//   if ($HLTest) {
//     echo '<p style="color:orange;">' . $data . '</p>';
//     echo '<br>';
//   }
// }
// function HLError($data) {
//   global $HLTest;
//   if ($HLTest) {
//     echo '<p style="color:red;">' . $data . '</p>';
//     echo '<br>';
//   }
// }

// function HLLogType($data) {
//   global $HLTest;
//   if ($HLTest) {
//     if (is_object($data) && is_callable($data)) {
//         echo 'is_object($data) && is_callable($data)';
//     } else if (is_object($data)) {
//       echo '$data 的类型是 ' . get_class($data);
//     } else {
//       echo "<pre>";
//       var_dump($data);
//       echo "</pre>";
//     }
//     echo '<br>';
//   }
// }

// function HLVar($data, $doIt=false) {
//   global $HLTest;
//   if ($doIt) {
//     echo "<pre>";
//     var_dump($data);
//     echo '<br>';
//     echo "</pre>";
//   } else if ($HLTest) {
//     echo "<pre>";
//     var_dump($data);
//     echo '<br>';
//     echo "</pre>";
//   }
// }

// function HLLogh1($data) {
//   global $HLTest;
//   if ($HLTest) {
//     echo '<h1>' . $data . '</h1>';
//     echo '<br>';
//   }
// }

// function HLLogh2($data) {
//   global $HLTest;
//   if ($HLTest) {
//     echo '<h2>' . $data . '</h2>';
//     echo '<br>';
//   }
// }

// function HLLogh3($data) {
//   global $HLTest;
//   if ($HLTest) {
//     echo '<h3>' . $data . '</h3>';
//     echo '<br>';
//   }
// }

// ###########################################

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

// HLLogh1('public\\index.php');
// HLError('$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);');
// // $app->bindings 中已经有 Illuminate\Contracts\Http\Kernel 这个 key 的键值对元素了。
// HLError('Illuminate\Contracts\Http\Kernel::class 是');
// HLLog(Illuminate\Contracts\Http\Kernel::class);// string(32) "Illuminate\Contracts\Http\Kernel"。
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
// exit;

//HLlogh1('App\Http\Kernel.php KernelInstance');
//HLVar($kernel->router->getRoutes());
/*
object(Illuminate\Routing\RouteCollection)#26 (4) {
  ["routes":protected]=>
  array(0) {
  }
  ["allRoutes":protected]=>
  array(0) {
  }
  ["nameList":protected]=>
  array(0) {
  }
  ["actionList":protected]=>
  array(0) {
  }
}
*/

// HLLogh1('public\\index.php');
// HLError('$response = $kernel->handle($request = Illuminate\Http\Request::capture());');
// $response = $kernel->handle(
//     $request = Illuminate\Http\Request::capture()
// );
// 拆分如下两步：
// 步骤1
$request = Illuminate\Http\Request::capture();
// $request 就是 Illuminate\Http\Request 的实例。
/*
HLVar(array_keys($app->instances));
array(13) {
  [0]=>
  string(3) "app"
  [1]=>
  string(30) "Illuminate\Container\Container"
  [2]=>
  string(6) "events"
  [3]=>
  string(4) "path"
  [4]=>
  string(9) "path.base"
  [5]=>
  string(9) "path.lang"
  [6]=>
  string(11) "path.config"
  [7]=>
  string(11) "path.public"
  [8]=>
  string(12) "path.storage"
  [9]=>
  string(13) "path.database"
  [10]=>
  string(14) "path.resources"
  [11]=>
  string(14) "path.bootstrap"
  [12]=>
  string(32) "Illuminate\Contracts\Http\Kernel"
}
可见 Request 对象本身还没有放在里面。是在 Kernel 的 sendRequestThroughRouter() 方法执行时存放的。
*/
// exit;

/*
HLlogh1('App\Http\Kernel.php KernelInstance22');
HLVar($kernel->router->getRoutes());
object(Illuminate\Routing\RouteCollection)#26 (4) {
  ["routes":protected]=>
  array(0) {
  }
  ["allRoutes":protected]=>
  array(0) {
  }
  ["nameList":protected]=>
  array(0) {
  }
  ["actionList":protected]=>
  array(0) {
  }
}
*/

// 步骤2
$response = $kernel->handle(
    $request
);
// exit;

// 证明是在 $kernel->handle($request) 时添加的路由。
// HLlogh1('App\Http\Kernel.php KernelInstance33');
// HLVar($kernel->router->getRoutes());
// object(Illuminate\Routing\RouteCollection)#26 (4) {

// HLLogh1('public\index.php');
// HLlogh1('$kernel->router->getGroupStack() 是');
// HLVar($kernel->router->getGroupStack());


// HLLogh1('public\\index.php');
// HLError('$response->send();');
$response->send();

// HLLogh1('public\\index.php');
// HLError('$kernel->terminate($request, $response);');
$kernel->terminate($request, $response);
